import 'dart:core';

import 'package:get/get.dart';

class UpdateInfoModel {
  /**
   * 当前设备版本
   */
  final String? version;

  /**
   * 设备类型
   */
  final Map<String, String>? deviceType;

  /**
   * 是否新版本
   */
  final bool? newVersion;

  /**
   * 中文更新内容
   */
  final String? updateContent;

  /**
   * 英语更新内容
   */
  final String? enUpdateContent;

  /**
   * 西班牙更新内容
   */
  final String? spainUpdateContent;

  /**
   * 意大利更新内容
   */
  final String? italianUpdateContent;

  /**
   * 葡萄牙更新内容
   */
  final String? portugueseUpdateContent;

  /**
   * 德国更新内容
   */
  final String? germanyUpdateContent;

  /**
   * 法国更新内容
   */
  final String? franceUpdateContent;

  /**
   * 升级包
   */
  final String? upgradePackage;

  UpdateInfoModel({
    this.version,
    this.deviceType,
    this.newVersion,
    this.updateContent,
    this.enUpdateContent,
    this.spainUpdateContent,
    this.italianUpdateContent,
    this.portugueseUpdateContent,
    this.germanyUpdateContent,
    this.franceUpdateContent,
    this.upgradePackage,
  });

  factory UpdateInfoModel.fromMap(dynamic map) {
    var temp;
    return UpdateInfoModel(
      version: map['version']?.toString(),
      deviceType: null == (temp = map['deviceType'])
          ? {}
          : (temp is Map
              ? temp
                  .map((key, map) => MapEntry(key!.toString(), map!.toString()))
              : {}),
      newVersion: null == (temp = map['newVersion'])
          ? null
          : (temp is bool
              ? temp
              : (temp is num
                  ? 0 != temp.toInt()
                  : ('true' == temp.toString()))),
      updateContent: map['updateContent']?.toString(),
      enUpdateContent: map['enUpdateContent']?.toString(),
      spainUpdateContent: map['spainUpdateContent']?.toString(),
      italianUpdateContent: map['italianUpdateContent']?.toString(),
      portugueseUpdateContent: map['portugueseUpdateContent']?.toString(),
      germanyUpdateContent: map['germanyUpdateContent']?.toString(),
      franceUpdateContent: map['franceUpdateContent']?.toString(),
      upgradePackage: map['upgradePackage']?.toString(),
    );
  }

  String? get updateContentWithLang =>
      switch ((Get.locale?.languageCode ?? '')) {
        "zh" => updateContent,
        "es" => spainUpdateContent,
        "it" => italianUpdateContent,
        "pt" => portugueseUpdateContent,
        "de" => germanyUpdateContent,
        "fr" => franceUpdateContent,
        _ => enUpdateContent,
      };
}
